using Arcane.Source.Data;
using Arcane.Source.Combat;
using Godot;

namespace Arcane.Source.UI
{
    public partial class Aura : Range
    {
        [Export]
        public TextureRect icon;
        [Export]
        public Label levelLabel;

        public Aura Bind(StringName name, BaseStatusEffect effect)
        {
            MaxValue = effect.Life;
            Value = effect.Life;
            effect.OnCountChange += SetCount;
            effect.OnLifeChange += SetLife;

            icon.Texture = GameDB.StatusEffect.GetIcon(name);

            return this;
        }

        public void SetLife(float life)
        {
            if (life > Value) 
                MaxValue = life;
            Value = life;
            if (life <= 0) 
                QueueFree();
        }

        public void SetCount(int count)
        {
            if (count <= 1)
            {
                levelLabel.Visible = false;
            }
            else
            {
                levelLabel.Visible = true;
                levelLabel.Text = count.ToString();
            }
        }
    }
}